AddCSLuaFile('custom.lua')

-- Admin Commands For E2

-- Armor
e2function void entity:setArmor( number Amt ) 
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	this:SetArmor( math.Round( math.Clamp( Amt, 0, 99999 ) ) )
end

--[[Blind - Not being used now, I can't figure out how to implement it. Help is welcome! 
e2function void entity:blind() 
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end]]

-- Cloak/Uncloak
e2function void entity:cloakPlayer( number Amt )
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	local r, g, b, a = this:GetColor()
	this:SetColor( Color( r, g, b, 255 - Amt))
end

e2function void entity:uncloakPlayer()
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	local r, g, b, a = this:GetColor()
	this:SetColor( Color( r, g, b, 255 ))
end

-- Freeze/Unfreeze - Uses the Lock/Unlock functions, so they can't respawn
e2function void entity:freezePlayer()
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	this:Lock()
end

e2function void entity:unfreezePlayer()
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	this:UnLock()
end

-- BY PHENIXBLAZE AKA THANATOS

-- God/Ungod
e2function void entity:god()
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	this:EnableGod()
end

e2function void entity:ungod()
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	this:DisableGod()
end

-- Health
e2function void entity:setHealth( number Amt )
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	this:SetHealth(math.Round( math.Clamp( Amt, 0, 99999 ) ) )
end

-- Ragdoll and Unragdoll! - Mostly just ripped from ULX, but it's still epic.
e2function void entity:ragdoll()
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	this.IsRagdolled = true
	
	local ragdoll = ents.Create( "prop_ragdoll" )
	local velocity = this:GetVelocity()
	ragdoll:SetPos( this:GetPos() )
	ragdoll:SetAngles( this:GetAngles() )
	ragdoll:SetModel( this:GetModel() )
	ragdoll:Spawn()
	ragdoll:Activate()
	this:SetParent( ragdoll )
	for i=1, 14 do
		ragdoll:GetPhysicsObjectNum( i ):SetVelocity( velocity )
	end
	this:Spectate( OBS_MODE_CHASE )
	this:SpectateEntity( ragdoll )
	this:StripWeapons()
	this.ragdoll = ragdoll
end

e2function void entity:unragdoll()
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	
	this:SetParent()
	local ragdoll = this.ragdoll
	this.ragdoll = nil
	
	if !ragdoll:IsValid() then
		this:Spawn()
	else
		local pos = ragdoll:GetPos()
		pos.z = pos.z + 10
		
		this:Spawn()
		this:SetPos( pos )
		this:SetVelocity( ragdoll:GetVelocity() )
		local yaw = ragdoll:GetAngles().yaw
		this:SetAngles( Angle( 0, yaw, 0 ))
		ragdoll:Remove()
	end
end

-- Slay
e2function void entity:slay()
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	if this:Alive() then
		this:Kill()
	else
		self.player:ChatPrint("This player is already dead!")
	end 
end

-- Spawn
e2function void entity:spawn()
	if !self.player:IsAdmin() then return end
	if !this:IsPlayer() then return end
	if !this:Alive() then
		this:Spawn()
	end
end

-- Make big boom!
e2function void createExplosion( vector Pos, number Radius, number Damage )
	if !self.player:IsAdmin() then return end
	local Pos = Vector( Pos[1], Pos[2], Pos[3] )
	local ED = EffectData()
	ED:SetOrigin(Pos)
	ED:SetScale(Radius*2)
	util.Effect( "Explosion", ED, true, true )
	util.BlastDamage( self.entity, self.player, Pos, math.Clamp( Radius, 0, 5000 ), math.Clamp( Damage, 1, 1000 ) )
end